const Subscription = require('egg').Subscription;


class DeletePCLoginInfo extends Subscription {

	static get schedule() {

		return {
			interval: '120m',
			type: 'worker',
			immediate: true,

			disable: false,
		};
	}


	async subscribe() {

		const { ctx } = this;

		const { app } = ctx;

		const redisSessions = await app.redis.get('member').hgetall('juyou_session_');

		Object.keys(redisSessions).forEach(async (key) => {
			const tmp = redisSessions[key];
			//ctx.logger.info(tmp);
			const arr = tmp.split('|');

			const now = new Date().getTime();

			//ctx.logger.info(now - parseInt(arr[2]));

			if(now - parseInt(arr[2]) > parseInt(arr[1]) ){
				ctx.logger.info(arr + ' 超过12小时,删除');
				await app.redis.get('member').hdel('juyou_session_', key);
			}

		})

	}

}

module.exports = DeletePCLoginInfo;